|
map::operator[]public member function
T& operator[] ( const key_type& x ); Access element If x matches the key of an element in the container, the function returns a reference to its mapped value.If x does not match the key of any element in the container, the function inserts a new element with that key and returns a reference to its mapped value. Notice that this always increases the map size by one, even if no mapped value is assigned to the element (the element is constructed using its default constructor). A call to this function is equivalent to: (*((this->insert(make_pair(x,T()))).first)).second
Parameters
Return valueA reference to the element with a key value equal to x.T is the second template parameter, which defines the type of the mapped values in the container. Example
Notice how the last access (to element 'd') inserts a new element in the set with that key and initialized to its default value (an empty string) even though it is accessed only to retrieve its value. Member function map::find does not produce this effect. Output:
ComplexityLogarithmic in size.See also
|